package com.song.pj.goods.dao;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class DefaultGoodsDao implements GoodsDao{
    @Autowired
    private DataSource dataSource;
    @Override
    public List<Map<String, Object>> findGoods() throws SQLException {
        Connection conn = dataSource.getConnection();

        Statement stat = conn.createStatement();

        String sql = "select * from tb_goods";
        ResultSet rs = stat.executeQuery(sql);

        List<Map<String,Object>> list = new ArrayList<>();


        while(rs.next()){
            Map<String,Object> map = new HashMap<>();
            map.put("id",rs.getInt(1) );
            map.put("name",rs.getString(1) );
//            map.put("remake",rs.getInt(1) );
//            map.put("id",rs.getInt(1) );
            list.add(map);
        }

        rs.close();
        return list;
    }
}
